package com.learn.job;

import io.netty.util.HashedWheelTimer;
import io.netty.util.Timeout;
import io.netty.util.Timer;
import io.netty.util.TimerTask;

import java.util.concurrent.TimeUnit;

/**
 * @author : Yu.Tan
 * @date : 2023/3/23 11:29
 * @desc : **
 */
public class HashedWheelTimerJob {
    public static void main(String[] args) {
        HashedWheelTimerTask task=new HashedWheelTimerTask(true);
        Timer timer = new HashedWheelTimer();
        timer.newTimeout(task, 5, TimeUnit.SECONDS);
        int i = 1;
        while (task.flag){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(i + "秒过去了");
            i++;
        }
        
    }

    static class HashedWheelTimerTask implements TimerTask{
        boolean flag;

        public HashedWheelTimerTask(boolean flag){
            this.flag=flag;
        }
        @Override
        public void run(Timeout timeout) throws Exception {
            System.out.println("要去数据库删除订单了。。。。");
            this.flag = false;
        }
    }
}
